<html>
<head><meta charset="utf-8"><title>global allocator fails to allocate isize::MAX · t-libs/wg-allocators · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/index.html">t-libs/wg-allocators</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/global.20allocator.20fails.20to.20allocate.20isize.3A.3AMAX.html">global allocator fails to allocate isize::MAX</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="181570627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/global%20allocator%20fails%20to%20allocate%20isize%3A%3AMAX/near/181570627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/global.20allocator.20fails.20to.20allocate.20isize.3A.3AMAX.html#181570627">(Nov 21 2019 at 18:34)</a>:</h4>
<p>I added the liballoc tests to alloc-wg in <a href="https://github.com/TimDiekmann/alloc-wg/pull/10" target="_blank" title="https://github.com/TimDiekmann/alloc-wg/pull/10">this PR</a>. The function <code>test_try_reserve</code> fails as the global allocator is not able to allocate <code>isize::MAX</code> bytes. Does the compiler use another allocator for testing liballoc? Or do I oversee something?</p>



<a name="181570779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/global%20allocator%20fails%20to%20allocate%20isize%3A%3AMAX/near/181570779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/global.20allocator.20fails.20to.20allocate.20isize.3A.3AMAX.html#181570779">(Nov 21 2019 at 18:36)</a>:</h4>
<p>At the current commit, it panics at <a href="https://github.com/TimDiekmann/alloc-wg/pull/10/files#diff-52a6f43527c89730431b8266b32d6edbR1132" target="_blank" title="https://github.com/TimDiekmann/alloc-wg/pull/10/files#diff-52a6f43527c89730431b8266b32d6edbR1132">line 1132-1134</a></p>



<a name="181570994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/global%20allocator%20fails%20to%20allocate%20isize%3A%3AMAX/near/181570994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/global.20allocator.20fails.20to.20allocate.20isize.3A.3AMAX.html#181570994">(Nov 21 2019 at 18:38)</a>:</h4>
<p>Precisely It calls </p>
<div class="codehilite"><pre><span></span><span class="cp">#[stable(feature = </span><span class="s">&quot;global_alloc&quot;</span><span class="cp">, since = </span><span class="s">&quot;1.28.0&quot;</span><span class="cp">)]</span><span class="w"></span>
<span class="cp">#[inline]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="k">fn</span> <span class="nf">alloc</span><span class="p">(</span><span class="n">layout</span>: <span class="nc">Layout</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="o">*</span><span class="k">mut</span><span class="w"> </span><span class="kt">u8</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">__rust_alloc</span><span class="p">(</span><span class="n">layout</span><span class="p">.</span><span class="n">size</span><span class="p">(),</span><span class="w"> </span><span class="n">layout</span><span class="p">.</span><span class="n">align</span><span class="p">())</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>with</p>
<div class="codehilite"><pre><span></span><span class="n">core</span>::<span class="n">alloc</span>::<span class="n">Layout</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">size</span>: <span class="mi">9223372036854775807</span><span class="p">,</span><span class="w"> </span><span class="n">align</span>: <span class="mi">1</span><span class="p">}</span><span class="w"></span>
</pre></div>


<p>and returns <code>NULL</code></p>



<a name="181571094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/global%20allocator%20fails%20to%20allocate%20isize%3A%3AMAX/near/181571094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/global.20allocator.20fails.20to.20allocate.20isize.3A.3AMAX.html#181571094">(Nov 21 2019 at 18:39)</a>:</h4>
<p>I <a href="https://www.wolframalpha.com/input/?i=9223372036854775807+in+hex" target="_blank" title="https://www.wolframalpha.com/input/?i=9223372036854775807+in+hex">double checked</a> the number, it's <code>isize::MAX</code>: <code>0x7fff_ffff_ffff_ffff</code></p>



<a name="181571548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/global%20allocator%20fails%20to%20allocate%20isize%3A%3AMAX/near/181571548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/global.20allocator.20fails.20to.20allocate.20isize.3A.3AMAX.html#181571548">(Nov 21 2019 at 18:44)</a>:</h4>
<p>Nevermind, it's a result of <code>AbortAlloc</code>.</p>



<a name="181572193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/global%20allocator%20fails%20to%20allocate%20isize%3A%3AMAX/near/181572193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/global.20allocator.20fails.20to.20allocate.20isize.3A.3AMAX.html#181572193">(Nov 21 2019 at 18:51)</a>:</h4>
<p>I'll open a new topic regarding <code>AbortAlloc</code> in combination with <code>try_reserve</code>.</p>



<a name="181599580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/global%20allocator%20fails%20to%20allocate%20isize%3A%3AMAX/near/181599580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Erich Gubler <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/global.20allocator.20fails.20to.20allocate.20isize.3A.3AMAX.html#181599580">(Nov 22 2019 at 00:30)</a>:</h4>
<p>I don't understand the context behind this test. Why would they try to allocate so much as a test?</p>



<a name="181599772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/global%20allocator%20fails%20to%20allocate%20isize%3A%3AMAX/near/181599772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mike Hommey <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/global.20allocator.20fails.20to.20allocate.20isize.3A.3AMAX.html#181599772">(Nov 22 2019 at 00:33)</a>:</h4>
<p>It's supposed to fail. Always. That's what is being tested.</p>



<a name="181609131"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/global%20allocator%20fails%20to%20allocate%20isize%3A%3AMAX/near/181609131" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tim Diekmann <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/global.20allocator.20fails.20to.20allocate.20isize.3A.3AMAX.html#181609131">(Nov 22 2019 at 04:23)</a>:</h4>
<p>It must not fail with a <code>CapacityOverflow</code>. Interesting for 16/32 bit platforms</p>



<a name="182122902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/global%20allocator%20fails%20to%20allocate%20isize%3A%3AMAX/near/182122902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/global.20allocator.20fails.20to.20allocate.20isize.3A.3AMAX.html#182122902">(Nov 28 2019 at 16:53)</a>:</h4>
<p><span class="user-mention" data-user-id="216785">@Tim Diekmann</span> are you on Windows ?</p>



<a name="182122948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/global%20allocator%20fails%20to%20allocate%20isize%3A%3AMAX/near/182122948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/global.20allocator.20fails.20to.20allocate.20isize.3A.3AMAX.html#182122948">(Nov 28 2019 at 16:54)</a>:</h4>
<p>This test has no problems if you have a system with overcommit with enough memory but small enough pointers</p>



<a name="182122974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/global%20allocator%20fails%20to%20allocate%20isize%3A%3AMAX/near/182122974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/global.20allocator.20fails.20to.20allocate.20isize.3A.3AMAX.html#182122974">(Nov 28 2019 at 16:54)</a>:</h4>
<p>You might want to check on which OSes does libstd run this test</p>



<a name="182123132"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/global%20allocator%20fails%20to%20allocate%20isize%3A%3AMAX/near/182123132" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/global.20allocator.20fails.20to.20allocate.20isize.3A.3AMAX.html#182123132">(Nov 28 2019 at 16:57)</a>:</h4>
<p>e.g., I expect this test to "fail by not failing" on, e.g., <code>x86_64-unknown-linux-gnu-x32</code></p>



<a name="182123191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/global%20allocator%20fails%20to%20allocate%20isize%3A%3AMAX/near/182123191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/global.20allocator.20fails.20to.20allocate.20isize.3A.3AMAX.html#182123191">(Nov 28 2019 at 16:58)</a>:</h4>
<p>where isize::MAX bytes is 4 Gbs, but that's a reasonable allocation on the target</p>



<a name="182123262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/197181-t-libs/wg-allocators/topic/global%20allocator%20fails%20to%20allocate%20isize%3A%3AMAX/near/182123262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/197181-t-libs/wg-allocators/topic/global.20allocator.20fails.20to.20allocate.20isize.3A.3AMAX.html#182123262">(Nov 28 2019 at 16:59)</a>:</h4>
<blockquote>
<p>It must not fail with a CapacityOverflow. I</p>
</blockquote>
<p>If by this you mean that this test must pass, and that this only happens if the <code>try_reserve</code> functions return <code>CapacityOverflow</code>, then that's correct - that's the intent of the test.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>